<template>
  <div>
    <h3>Count组件的求和为：{{sum}}</h3>
    <h3>人员信息</h3>
    <input v-model="name" type="text" placeholder="请输入名字" />
    <button @click="add">添加</button>
    <ul>
      <li v-for="item in personsList" :key="item.id">{{ item.name }}</li>
    </ul>
  </div>
</template>

<script>
import { nanoid } from "nanoid";
import { mapState } from "vuex";
export default {
  name: "Person",
  data() {
    return {
      name: "",
    };
  },
  components: {},
  computed: {
    ...mapState({ personsList: "personsList" }),
    ...mapState({ sum: "sum" }),
  },
  mounted() {},
  methods: {
    add() {
      const personObj = { id: nanoid(), name: this.name };
      this.$store.commit("ADD_PERSON", personObj);
      console.log(personObj);
    },
  },
};
</script>

<style scoped>
</style>
